#ifndef CNC_UI_MANAGER_H
#define CNC_UI_MANAGER_H

#include "uimgr_.h"
#include <bcm/bcm.h>

namespace cnc {

	namespace ui {

		class Manager : public bcm::Identifier<bcm::Component>,
			ManagerImpl
		{
		protected:
			Manager() : bcm::Identifier<bcm::Component>("uimgr", "User Interface Manager")
			{
			}
		protected:
			virtual bcm::IdentifierData *getProvidedInterfaceTable()
			{
				static bcm::IdentifierData idData[] = {
					{ "taskctl", "Task Control" },
					{ "uiservs", "User Interface Services" },
					{ 0, 0 }
				};
				return idData;
			}
			virtual bcm::IdentifierData *getRequiredInterfaceTable()
			{
				static bcm::IdentifierData idData[] = {
					{ "enventities", "Environment Entities" },
					{ "millpdata", "Mill Persistent Data" },
					{ "gdata", "Global Data" },
					{ "progmgr", "Program Manager" },
					{ 0, 0 }
				};
				return idData;
			}
			virtual bcm::Interface *getInterface(const char *id)
			{
				if (std::string("taskctl") == id)
					return getTaskControl();
				else if (std::string("uiservs") == id)
					return getServices();
				return 0;
			}
			virtual bool setInterface(bcm::Interface *iface)
			{
				if (iface == 0)
					return false;
				if (std::string("enventities") == iface->getID()) {
					cnc::rtl::EnvironmentEntities *env = dynamic_cast<cnc::rtl::EnvironmentEntities *>(iface);
					if (env == 0)
						return false;
					setEnvironmentEntities(env);
				} else if (std::string("millpdata") == iface->getID()) {
					cnc::base::MillPersistentData *millpdata = dynamic_cast<cnc::base::MillPersistentData *>(iface);
					if (millpdata == 0)
						return false;
					setMillPersistentData(millpdata);
				} else if (std::string("gdata") == iface->getID()) {
					cnc::base::GlobalData *gd = dynamic_cast<cnc::base::GlobalData *>(iface);
					if (gd == 0)
						return false;
					setGlobalData(gd);
				} else if (std::string("progmgr") == iface->getID()) {
					cnc::compiler::ProgramManager *pm = dynamic_cast<cnc::compiler::ProgramManager *>(iface);
					if (pm == 0)
						return false;
					setProgramManager(pm);
				} else
					return false;
				return true;
			}
		public:
			static Manager &instance(bcm::GetComponentResult *result)
			{
				static Manager object;
				if (result != 0)
					*result = object.result_;
				return object;
			}
		};

	} // namespace ui

} // namespace cnc

#endif

